#ifndef  __WORKFLOW_CFG_H__
#define  __WORKFLOW_CFG_H__

#ifdef   WORKFLOW_CFG_GLOBALS
#define  WORKFLOW_CFG_EXT
#else
#define  WORKFLOW_CFG_EXT  extern
#endif

/*******************公共头**********************/
typedef enum
{
    ManualType=0,
    AutoType,
}STARTTYPE;

typedef enum
{
    REM_DEVICE_MOTOR=1,//电机顺逆
    REM_DEVICE_PF,//PF
    REM_DEVICE_HZ,//Hz
}REM_DEVICE_TYPE;

/* 控制命令 */
typedef enum
{
    START_ENERGY_METER = 0x10,  // 启动电能计量
    PAUSE_ENERGY_METER = 0x11,  // 暂停电能计量
    STOP_AND_RESET_ENERGY = 0x12, // 电能停止并清零
    STOP_TESTFLOW=0x1A,  //停止当前流程
    REST_TESTFLOW=0x1B,  //复位测试流程
    START_TUNING0APF=0x20,//进行100%有功功率整定测试
    START_TUNING08PF=0x21,//进行60%有功功率整定测试
    START_TUNING06A04PF=0x22,//进行60%电流整定测试
    START_VOLATILITY = 0x23, // 进行波动率测试
    SURGE_INCREASE_TEST = 0x24, // 进行突加测试
    START_LOADUNLOAD = 0x25, // 进行突卸测试
    START_LOWFREPROTE = 0x26, // 进行低频保护测试
    START_STARTSTOP = 0x27, // 进行启停测试
    START_BUILDPRESSURE = 0x28, // 进行建压测试
    START_EXTEXCITATION = 0x2A, // 进行极限励磁测试
    WAVEFORM_ANALYSIS = 0x2B, // 进行波形分析
    START_CLOSEGATE = 0x2C, // 进行同步合闸
    START_OPENGATE = 0x2D, // 进行分闸
    START_RECORDING = 0x31, // 启动录波
    STOP_RECORDING = 0x30, // 停止录波
    START_PRIMEMOTOR = 0x60,//启动原动机
    STOP_PRIMEMOTOR =0x61,//停止原动机
    CHANGE_TOManualType= 0xA1A1,//切换为手动
    CHANGE_TOAutoType = 0x5151,//切换为自动
}CONTROL_COMMANDS;
/* 电机或功率因素调节 */
typedef enum
{
    ORD_PHASE_MOTOR=0x1,//相位和有功调节电机
    ORD_EXCV_MOTOR,//励磁分压电机
    ORD_EXCI_MOTOR,// 励磁分流电机
    ORD_EXCI2_MOTOR,//励磁分流电机2（暂时不用）
    ORD_BUILD_VOL_MOTOR,//建压电机
    ORD_VOL_PF_MOTOR,//电压和功率因素调节
    ORD_PRIME_MOTOR,//原动机-转速
    ORD_FOR_100=0xA1,//顺时针调节100ms或功率因素加0.05、或原动机+0.1HZ
    ORD_FOR_200,     //顺时针调节200ms或功率因素加0.1、或原动机+0.2HZ
    ORD_FOR_500,     //顺时针调节500ms或功率因素加0.2、或原动机+0.5HZ
    ORD_REV_100=0x51,//逆时针调节100ms或功率因素减0.05、或原动机-0.1HZ
    ORD_REV_200,     //逆时针调节200ms或功率因素减0.1、或原动机-0.2HZ
    ORD_REV_500,     //逆时针调节500ms或功率因素减0.2、或原动机-0.5HZ
}MOTOR_COMMANDS;
/*******************内部指令状态**********************/

#define ShareInOrderSta_BVolLimVal                   0 //建压电机到低限位指令
#define ShareInOrderSta_BVolSetVal                   1 //建压电机到指定值指令
#define ShareInOrderSta_BVolSetTime                  2 
#define ShareInOrderSta_ExcvLimVal                   3 //励磁分压低限位指令
#define ShareInOrderSta_ExcvSetVal                   4 
#define ShareInOrderSta_ExcvSetTime                  5 
#define ShareInOrderSta_ExciLimVal                   6 
#define ShareInOrderSta_ExciSetVal                   7 
#define ShareInOrderSta_ExciSetTime                  8 
#define ShareInOrderSta_PriMoverStart                9 //原动机启动并到指定Hz指令
#define ShareInOrderSta_PriMoverStop                 10 
#define ShareInOrderSta_TOTNum                      (ShareInOrderSta_PriMoverStop+1)

#define PIDOrderSta_DEF_NONE                         0 //无操作/空闲
#define PIDOrderSta_DEF_PIDREQ                       1 //PID执行请求  
#define PIDOrderSta_DEF_RUNNING                      2 //PID执行运行中 
#define PIDOrderSta_DEF_SUCCESSBEF                   3 //PID执行成功前
#define PIDOrderSta_DEF_SUCCESS                      4 //PID执行成功等待外部确认
#define PIDOrderSta_DEF_PIDHLIMIT                    5 //PID执行高限位
#define PIDOrderSta_DEF_PIDLLIMIT                    6 //PID执行低限位
#define PIDOrderSta_DEF_EMSTOP                       7 //PID紧急停机
#define PIDOrderSta_DEF_TOTNum                       (PIDOrderSta_DEF_EMSTOP+1)
WORKFLOW_CFG_EXT uint8_t ShareBuffer_SharePIDOrderSta[ShareInOrderSta_TOTNum];//**电机到** - PID状态


/*******************Workflow Status define**********************/
#define WorkflowMode_Standby                          0 
#define WorkflowMode_BuildUpVoltage                   1 //建压
#define WorkflowMode_Volatility                       2 
#define WorkflowMode_ExtExcitation                    3 
#define WorkflowMode_LowFreProte                      4
#define WorkflowMode_Tuning0APF                       5
#define WorkflowMode_Tuning08PF                       6
#define WorkflowMode_Tuning06A04PF                    7
#define WorkflowMode_LoadUnLoad                       8
#define WorkflowMode_StartStop                        9
#define WorkflowMode_CloseGate                        10
#define WorkflowMode_StopPriMover                     11 //停机
#define WorkflowMode_Ending                           (WorkflowMode_StopPriMover+1)
#define WorkflowMode_Maximum                          WorkflowMode_Ending  
#define WorkflowMode_Null                             255  
#define WorkflowMode_TOTNum                           (WorkflowMode_Maximum+1)
WORKFLOW_CFG_EXT uint8_t ShareBuffer_WorkflowMode;
WORKFLOW_CFG_EXT uint8_t ShareBuffer_ReStartWorkflowMode;//远程启动模式


/*------------------- 定义测试平台工作状态的事件 -----------------*/
#define GenWorkStaOrd_Running                       0
#define GenWorkStaOrd_AlarmWarn                     1
#define GenWorkStaOrd_AlarmShutDown                 2 //停机告警
#define GenWorkStaOrd_ManualStart                   3
#define GenWorkStaOrd_AutoStart                     4
#define GenWorkStaOrd_RequestStop                   5
#define GenWorkStaOrd_AlarmReset                    6

#define GenWorkStaOrd_TOTBitNum                     (GenWorkStaOrd_AlarmReset+1)
#define GenWorkStaOrd_TOTByteNum                    ((GenWorkStaOrd_TOTBitNum-1)/8+1)
WORKFLOW_CFG_EXT uint8_t FlagShareBuffer_GenWorkingSta[GenWorkStaOrd_TOTByteNum];


/*******************建压流程步骤里面的周期**********************/
#define WorkflowPeriod_Entry                          0
#define WorkflowPeriod_1st                            1
#define WorkflowPeriod_2nd                            2
#define WorkflowPeriod_3nd                            3
#define WorkflowPeriod_4nd                            4
#define WorkflowPeriod_5nd                            5
#define WorkflowPeriod_Maximum                        WorkflowPeriod_5nd
WORKFLOW_CFG_EXT uint8_t ShareBuffer_WorkflowPeriod;

WORKFLOW_CFG_EXT uint8_t ShareBuffer_WorkflowStep;

#define WFWave_VolatilityCollect            0
#define WFWave_VolatilityCollectEnd         1
#define WFWave_SteadyVoltage                2  
#define WFWave_SteadyVoltageEnd             3  
#define WFWave_LowFreProte                  4
#define WFWave_LowFreProteEnd               5
#define WFWave_StartStop                    6
#define WFWave_StartStopEnd                 7
#define WFWave_LoadUnLoad                   8
#define WFWave_LoadUnLoadEnd                9
#define WFWave_BuildUpVoltage               10
#define WFWave_BuildUpVoltageEnd            11
#define WFWave_Waveform                     12
#define WFWave_WaveformEnd                  13
#define WFWave_TOTNum                        (WFWave_WaveformEnd+1)
#define WFWave_TOTByteNum                    ((WFWave_TOTNum-1)/8+1)
WORKFLOW_CFG_EXT uint8_t FlagShareBuffer_WFWave[WFWave_TOTByteNum];


/******************* Raw Alarm 原始的告警 *******************/
#define RawAlarm_DI_BVOL_LLimit                     0              /* Byte0 */
#define RawAlarm_DI_BVOL_HLimit                     1   
#define RawAlarm_DI_EXCV_LLimit                     2   
#define RawAlarm_DI_EXCV_HLimit                     3   
#define RawAlarm_DI_EXCI_LLimit                     4   
#define RawAlarm_DI_EXCI_HLimit                     5   
#define RawAlarm_DI_EXCI2_LLimit                    6   
#define RawAlarm_DI_EXCI2_HLimit                    7                 
#define RawAlarm_DI_Reserved10                      8  //相位或有功调节电机触发最小限位 /* Byte1 */ 
#define RawAlarm_DI_Reserved11                      9  //相位或有功调节电机触发最大限位
#define RawAlarm_DI_EXCV2_LLimit                    10              
#define RawAlarm_DI_EXCV2_HLimit                    11   
#define RawAlarm_DI_AUX_IN1                         12    
#define RawAlarm_DI_Reserved13                      13   
#define RawAlarm_DI_Reserved14                      14   
#define RawAlarm_DI_Reserved15                      15              
#define RawAlarm_Reserved16                         16             /* Byte2 */   
#define RawAlarm_Reserved17                         17               
#define RawAlarm_Reserved18                         18               
#define RawAlarm_Reserved19                         19               
#define RawAlarm_EmergencyStop                      20 //紧急停机              
#define RawAlarm_Reserved21                         21               
#define RawAlarm_Reserved22                         22               
#define RawAlarm_Reserved23                         23               
#define RawAlarm_BVOL_Mac_Fail                      24 //建压电机调节超时         /* Byte3 */  
#define RawAlarm_BVOL_Invalid                       25 //建压电机调节失效
#define RawAlarm_BVOL_LLimit                        26 //建压电机调节达到最小限位
#define RawAlarm_BVOL_HLimit                        27 //建压电机调节达到最大限位
#define RawAlarm_REMVOL_Low                         28 //发电机剩磁电压低
#define RawAlarm_VOLVAL_High                        29 //AVR建压值过高
#define RawAlarm_BVOL_Timeout                       30 //建压测试超时
#define RawAlarm_CLOSEGATE_Fail                     31 //合闸失败    
#define RawAlarm_OPENGATE_Fail                      32 //分闸失败 /* Byte4 */
#define RawAlarm_EXCV_MAC_Fail                      33 //励磁分压电机1调节超时
#define RawAlarm_EXCV_MOT_Invalid                   34 //励磁分压电机1调节失效
#define RawAlarm_EXCV_MOT_LLimit                    35 //励磁分压电机1调节达到最小限位
#define RawAlarm_EXCV_MOT_HLimit                    36 //励磁分压电机1调节达到最大限位
#define RawAlarm_EXCI_OPEN_Fail                     37 //励磁分流器断开失败
#define RawAlarm_EXCI_MAC_Fail                      38 //励磁分流电机1调节超时
#define RawAlarm_EXCI_MOT_Invalid                   39 //励磁分流电机1调节失效  
#define RawAlarm_EXCI_MOT_LLimit                    40 //励磁分流电机1调节达到最小限位 /* Byte5 */ 
#define RawAlarm_EXCI_MOT_HLimit                    41 //励磁分流电机1调节达到最大限位
#define RawAlarm_StartPriMotor_Fail                 42 //原动机启动失败
#define RawAlarm_StopPriMotor_Fail                  43 //原动机停机失败
#define RawAlarm_P_Fail                             44 //有功调节失败（没有到指定值）
#define RawAlarm_P_Invalid                          45 //有功调节电机失效
#define RawAlarm_PF_Fail                            46 //功率因素调节失败（没有到指定值）
#define RawAlarm_PF_Invalid                         47 //功率因素调节电机失效   /* Byte6 */ 
#define RawAlarm_REV1                               48 // 负载机励磁调节失败
#define RawAlarm_REV2                               49 // 负载机相位调节失败
#define RawAlarm_REV3                               50 // 负载机相位调节电机失效
#define RawAlarm_REV4                               51 // 同步合闸超时
#define RawAlarm_GENAppointFre_Fail                 52 //发电机没达到指定频率
#define RawAlarm_EXCI2_MAC_Fail                     53 //励磁分流电机2调节超时
#define RawAlarm_EXCI2_MOT_Invalid                  54 //励磁分流电机2调节失效
#define RawAlarm_EXCI2_MOT_LLimit                   55 //励磁分流电机2调节达到最小限位  /* Byte7 */ 
#define RawAlarm_EXCI2_MOT_HLimit                   56 //励磁分流电机2调节达到最大限位
#define RawAlarm_EXCV2_MAC_Fail                     57 //励磁分压电机2调节超时
#define RawAlarm_EXCV2_MOT_Invalid                  58 //励磁分压电机2调节失效
#define RawAlarm_EXCV2_MOT_LLimit                   59 //励磁分压电机2调节达到最小限位
#define RawAlarm_EXCV2_MOT_HLimit                   60 //励磁分压电机2调节达到最大限位
#define RawAlarm_REV61                              61 //
#define RawAlarm_REV62                              62 //
#define RawAlarm_REV63                              63 //
#define RawAlarm_REV64                              64 //                              /* Byte8 */
#define RawAlarm_REV65                              65 //
#define RawAlarm_REV66                              66 //
#define RawAlarm_REV67                              67 //

#define RawAlarm_TOTBitNum                          (RawAlarm_REV67+1)
#define RawAlarm_TOTByteNum                         ((RawAlarm_TOTBitNum-1)/8+1)
WORKFLOW_CFG_EXT uint8_t FlagShareBuffer_RawAlarm[RawAlarm_TOTByteNum];	//原始的告警标志，按位存储

/*--------------------------输出告警检测范围-----------------------------------*/
WORKFLOW_CFG_EXT uint8_t OutAlarmWarnSwitchTable[];


WORKFLOW_CFG_EXT uint8_t ShareBuffer_WorkflowRunMode;//启动模式
WORKFLOW_CFG_EXT uint16_t LIMITAlarm;//限位告警
WORKFLOW_CFG_EXT uint64_t ControlAlarm;//控制类告警
WORKFLOW_CFG_EXT uint16_t FlowDataStatus;//流程测试结果数据状态 - DATASTATUS
WORKFLOW_CFG_EXT uint8_t switchState;//合闸状态
WORKFLOW_CFG_EXT void ChangeGenWorkingSta(uint8_t GenWorkStaOrd_x,uint8_t OperaOpt);
#endif